<template>
  <div class="app-container">
    <promptMsg />
    <!-- 头部 -->
    <Head :flag="false" />
    <!-- 表格 -->
    <div class="table">
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        @selection-change="handleSelectionChange"
        :header-cell-style="{ color: '#000000', fontSize: '15px' }"
      >
        <el-table-column type="selection" align="center"> </el-table-column>
        <el-table-column prop="gameName" label="游戏名称" align="center">
        </el-table-column>
        <el-table-column prop="level" label="分级类别" align="center">
        </el-table-column>
        <el-table-column prop="mount" label="商品数量" align="center">
        </el-table-column>
        <el-table-column prop="" label="是否显示" align="center">
          <template slot-scope="scope">
            <el-switch
              :value="scope.row.is_show === 1 ? true : false"
              active-color="#13ce66"
              inactive-color="#DCE0E7"
              @change="change(scope.$index, scope.row)"
            >
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column prop="sort" label="排序" align="center">
        </el-table-column>
        <el-table-column prop="does" label="操作" align="center" width="500px">
          <template slot-scope="scope">
            <el-button
              size="medium"
              type="primary"
              @click="handleEdit(scope.$index, scope.row)"
              >编辑
            </el-button>
            <el-button
              size="medium"
              type="danger"
              @click="handleDel(scope.$index, scope.row)"
              >删除
            </el-button>
            <el-button
              size="medium"
              type="success"
              @click="handleAdd(scope.$index, scope.row)"
              >新增下一级
            </el-button>
            <el-button
              size="medium"
              type="warning"
              @click="handleNext(scope.$index, scope.row)"
              >查看下一级
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.pageIndex"
      :limit.sync="listQuery.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script async>
import Head from "@/components/type_header";
import pagination from "@/components/Pagination";
import { getType } from "@/api/news";

export default {
  name: "commodity_type",
  components: {
    Head, //头部
    pagination, //分页
  },
  data() {
    return {
      listLoading: false,
      total: 0,
      listQuery: {
        pageIndex: 1,
        pageSize: 10,
      },
      tableData: [],
      multipleSelection: [],
    };
  },
  created() {
    //请求数据
    getType().then((res) => {
      if (res.code === 200) {
        console.log();
        this.tableData = res.res;
        this.total = this.tableData.length;
      }
    });
    //分页
    this.getList();
  },
  methods: {
    //分页
    getList(val) {
      console.log(val);
      this.listLoading = true;

      this.listLoading = false;
    },
    //开关
    change(index, val) {
      val.is_show = val.is_show === 1 ? 2 : 1;
      console.log(index, val);
    },
    //编辑
    handleEdit(index, val) {
      console.log(index, val);
      this.$router.push('/commodity_manager/typeEdit')
    },
    //删除
    handleDel(index, val) {
      console.log(index, val);
    },
    //新增下一级
    handleAdd(index, val) {
      console.log(index, val);
      this.$router.push('/commodity_manager/typeAdd')
    },
    //查看下一级
    handleNext(index, val) {
      console.log(val.id);
      this.$router.push({
        name: "commodity_typeNext",
        params: {
          id: val.id,
        },
      });
    },
    //批量删除
    handleSelectionChange(val) {
      this.multipleSelection = val;
      console.log(val);
    },
  },
};
</script>
<style scoped lang="scss">
.app-container {
  min-width: 1050px;

  .table {
    width: 100%;
    margin: 0 auto;
    margin-top: 30px;
    min-width: 1200px;
  }
}
</style>
